/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.apt.AddNewsBean;

import java.sql.Connection;
import java.sql.Date;
import java.sql.PreparedStatement;
import java.text.SimpleDateFormat;
import javax.servlet.http.HttpServletRequest;

import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;
import org.apt.connectDB.MyConnect;

/**
 *
 * @author MinhThang
 */
public class AdminAddNewsBean extends org.apache.struts.action.ActionForm {
    private String txtTitle;
    private String txtSummary;
    private String editorDefault;
    private String txtAuthor;
   
    public AdminAddNewsBean() {
        super();
        // TODO Auto-generated constructor stub
    }

    public boolean AddNews(){
        Connection conn=null;
        PreparedStatement ps=null;
        String sql="INSERT INTO News ( Title ,Summary , Content , DayPost , Author ,Status ,Description) VALUES(?,?,?,?,?,?,?)";
        //Lay gio he thong
        Date todayD=new Date(System.currentTimeMillis());
        //Khai bao dinh dang ngay thang
        SimpleDateFormat dayFormat= new SimpleDateFormat("dd/MM/yyyy");
        //parse ngay thang sang dinh dang va chuyen thanh string.
        String todayS=dayFormat.format(todayD.getTime());
        try {
            conn=MyConnect.getConnection();
            ps=conn.prepareCall(sql);
            ps.setString(1, getTxtTitle());
            ps.setString(2, getTxtSummary());
            ps.setString(3, getEditorDefault());
            ps.setString(4, todayS);
            ps.setString(5, getTxtAuthor());
            ps.setBoolean(6, true);
            ps.setString(7, "");
            ps.executeUpdate();
            return true;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return  false;
    }
    /**
     * This is the action called from the Struts framework.
     * @param mapping The ActionMapping used to select this instance.
     * @param request The HTTP Request we are processing.
     * @return
     */
   

    /**
     * @return the txtTitle
     */
    public String getTxtTitle() {
        return txtTitle;
    }

    /**
     * @param txtTitle the txtTitle to set
     */
    public void setTxtTitle(String txtTitle) {
        this.txtTitle = txtTitle;
    }

    /**
     * @return the txtSummary
     */
    public String getTxtSummary() {
        return txtSummary;
    }

    /**
     * @param txtSummary the txtSummary to set
     */
    public void setTxtSummary(String txtSummary) {
        this.txtSummary = txtSummary;
    }

    /**
     * @return the txtAuthor
     */
    public String getTxtAuthor() {
        return txtAuthor;
    }

    /**
     * @param txtAuthor the txtAuthor to set
     */
    public void setTxtAuthor(String txtAuthor) {
        this.txtAuthor = txtAuthor;
    }

    /**
     * @return the editorDefault
     */
    public String getEditorDefault() {
        return editorDefault;
    }

    /**
     * @param editorDefault the editorDefault to set
     */
    public void setEditorDefault(String editorDefault) {
        this.editorDefault = editorDefault;
    }

    /**
     * @return the EditorDefault
     */
  
}
